<?php
/**
 * Created by PhpStorm.
 * User: sunku
 * Date: 2018/2/28
 * Time: 18:05
 */

namespace Admin\Logic;
use Think\Model;

class DocumentLogic extends Model
{
    protected $trueTableName = 'wz_document';
    /**
     * @param $params
     * @return mixed
     */
    public function searchDocumentList($params) {
        $result = D('Resource/Document', 'Service')->searchDocumentList($params);
        return $result;
    }

    /**
     * @param $params
     * @param $fields
     * @return mixed
     */
    public function getDocumentInfo($params, $fields = '') {
        $result = D('Resource/Document', 'Service')->getDocumentInfo($params, $fields);
        return $result;
    }
    /**
     * @param $params
     * @return mixed
     */
    public function updateDocumentInfo($params) {
        $result = D('Resource/Document', 'Service')->updateDocumentInfo($params);
        return $result;
    }
    /**
     * @param $params
     * @return mixed
     */
    public function addDocument($params) {
        $result = D('Resource/Document', 'Service')->addDocument($params);
        return $result;
    }

    /**
     * @param $params
     * @return string
     */
    public function ajaxDeleteDoc($params) {
        $public = C('STATIC_PATH');
        $id = $params['id'];
        $child = D('Resource/Document','Service')->getDocumentInfo(['pid'=>$id]);
        if (!empty($child)) {
            return Response(2001, '不能删除有文件的目录');
        }
        $docInfo = D('Resource/Document','Service')->getDocumentInfo(['id'=>$id]);
        if(!$docInfo){
            return Response(2001,"未查询到该文档信息");
        }
        unlink($public.$docInfo['file_path']);
        $result = D('Resource/Document', 'Service')->deleteDocument($params);
        return $result;
    }
}